﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

using log4net;

namespace VDataAdapter.PriceServerAdapter
{
    /// <summary>
    /// This class print event received from price server to log
    /// </summary>
    class PriceServerLogEventHandler : IPriceServerEventHandler
    {
        private TextWriter tw = new StreamWriter("PriceServerEvents.log");

        private static ILog _log = LogManager.GetLogger(typeof(PriceServerLogEventHandler));

        public PriceServerLogEventHandler()
        {
            _log.Info("Initialize PriceServerLogEventHandler");
            tw.WriteLine("Initialize PriceServerLogEventHandler");
            tw.Flush();
        }

        public void GetFirstTime(IDictionary<string, PriceLibrary.PriceService.StockBase> basePrices, IDictionary<string, PriceLibrary.PriceService.StockBase> top3Prices)
        {
            _log.Info("GetFirstTime: " + " BasePrices: " + basePrices.Count.ToString() + " Top3Prices: " + top3Prices.Count.ToString());
            tw.WriteLine("GetFirstTime: " + " BasePrices: " + basePrices.Count.ToString() + " Top3Prices: " + top3Prices.Count.ToString());
            tw.Flush();
        }

        public void Top3PricesStock_Changed(IDictionary<string, PriceLibrary.PriceService.StockBase> top3Prices)
        {
            tw.WriteLine("Top3PricesStock Count: " + top3Prices.Count.ToString());
            tw.Flush();
        }

        public void MarketInfo_Changed(IDictionary<int, PriceLibrary.PriceService.MarketInfo> maketinfos)
        {
            tw.WriteLine("MarketInfo Count: " + maketinfos.Count.ToString());
            tw.Flush();
        }

        public void PutThroughTopPrices_Changed(IList<PriceLibrary.PriceService.StockInfoDyns> newstockbase)
        {
            tw.WriteLine("PutThough Count: " + newstockbase.Count.ToString());
            tw.Flush();
        }

        public void PutThroughTransactions_Changed(IList<PriceLibrary.PriceService.Transaction> newstockbase)
        {
            tw.WriteLine("PutThroughTransaction Count: " + newstockbase.Count.ToString());
            tw.Flush();
        }

        public void Transactions_Changed(IList<PriceLibrary.ChartService.Transaction> transactions, int countNumber, int totalCountNumber)
        {
            tw.WriteLine("Transaction Count: " + transactions.Count.ToString() + " countNo: " + countNumber.ToString() + " totalCount: " + totalCountNumber.ToString());
            tw.Flush();
        }

        public void ConnectionErrorHandler(Exception ex)
        {
            tw.WriteLine("Exception: " + ex.Message);
            tw.Flush();
        }
    }
}
